package wykop.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Streams {

	public static byte[] readFully(final InputStream is) throws IOException {
		final ByteArrayOutputStream buffer = new ByteArrayOutputStream();

		int nRead;
		final byte[] data = new byte[16384];

		while ((nRead = is.read(data, 0, data.length)) != -1) {
			buffer.write(data, 0, nRead);
		}

		try {
			buffer.flush();
		} catch (final IOException e) {
			throw new RuntimeException();
		}

		return buffer.toByteArray();
	}

}
